package twoRegInstructions;

import java.io.FileNotFoundException;
import java.io.IOException;

import main.MIPSSimulator;



public class Sw extends MIPSTwoRegInstruction {
	public Sw(String input) throws FileNotFoundException, IOException {
		super(input);
		myName = "sw";
	}

	@Override
	public void execute() {
		int wordToStore = MIPSSimulator.myRegisters.get(myRegisterOne);
		int firstBytes = wordToStore & 0xFF000000 >> 24;
		int secondBytes = wordToStore & 0xFF0000 >> 16;
		int thirdBytes = wordToStore & 0xFF00 >> 8;
		int fourthBytes = wordToStore & 0xFF;
		int regTwo = MIPSSimulator.myRegisters.get(myRegisterTwo);
		int regTwoAddress = MIPSSimulator.addressConversion(regTwo);
		MIPSSimulator.myStack[regTwoAddress + myImmediateValue] = firstBytes;
		MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 1] = secondBytes;
		MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 2] = thirdBytes;
		MIPSSimulator.myStack[regTwoAddress + myImmediateValue + 3] = fourthBytes;
	}
	
	public String toString(){
		return myName + " " + myRegisterOne +", " + myImmediateValueString + "(" + myRegisterTwo + ")";
	}
}